package com.wu.family.publish;

import java.util.ArrayList;
import java.util.List;

import com.wu.family.R;



import com.wu.family.utils.img.BitmapMgrImpl;

import android.R.integer;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class PublishImageAdapter extends BaseAdapter {
	private ArrayList<Bitmap> img_list ; 
	private Context mContext; 
	private ArrayList<String> url_list = null;
	public PublishImageAdapter(Context context, List<Bitmap> img_list) {
		mContext = context;
		this.img_list = (ArrayList<Bitmap>) img_list;
		
//		if(pic_ids != null && pic_ids.size() != 0) {
//			pic_array_id.addAll(pic_ids);
//		}
//		pic_array_id.add(R.drawable.add);
	}
	public PublishImageAdapter(Context context, ArrayList<String> url_list) {
		mContext = context;
		this.url_list = url_list;
	}
	@Override
	public int getCount() {
		return img_list != null?img_list.size():url_list.size();
	}

	@Override
	public Object getItem(int arg0) {
		return img_list != null?img_list.get(arg0):url_list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		ImageView img = (ImageView)arg1;
		if(img == null) {
			img = new ImageView(mContext);
			img.setScaleType(ScaleType.CENTER_CROP);
		}
		if( url_list != null ){
			img.setImageBitmap(BitmapMgrImpl.getInstance().loadBitmap(url_list.get(arg0), img, null));
		}else{
			img.setImageBitmap(img_list.get(arg0));
		}
		img.setLayoutParams(new Gallery.LayoutParams((int)mContext.getResources().getDimension(R.dimen.galley_high),
										(int)mContext.getResources().getDimension(R.dimen.galley_high)));
		return img;
	}
	
}
